export class Picker {
	constructor(viewer, icesium) {
		this._viewer = viewer;
		this._iCesium = icesium;
		this._handler = undefined;
	}

	addPickerListen(callback) {
		const handler = new this._iCesium.ScreenSpaceEventHandler(this._viewer.canvas);
		handler.setInputAction((ev) => {
			const Cartesian3Rlt = this._viewer.scene.pickPosition(ev.position);
			const carto = this._iCesium.Cartographic.fromCartesian(Cartesian3Rlt);
			const longitude = this._iCesium.Math.toDegrees(carto.longitude);
			const latitude = this._iCesium.Math.toDegrees(carto.latitude);
			const height = carto.height;
			const rlt = {
				Cartesian: Cartesian3Rlt,
				World: {
					longitude,
					latitude,
					height
				}
			};
			callback && callback(rlt);
		}, this._iCesium.ScreenSpaceEventType.LEFT_CLICK);
		this._handler = handler;
		return true;
	}

	removePickerListen() {
		this._handler && this._handler.destroy();
		return true;
	}
}
